<template>
    <div class="table-box">
        <TableHead :btns="btns" v-show="!hideHead" title="数据列表" :table="table" :search="search"
                   :index="index"></TableHead>

        <component :is="getTable" :data="data0||data" :tableData="tableData" :table="table" :delUrl="delUrl"
                   :type="type"></component>

        <el-pagination v-show="(data0&&data0.length>0)||data.length>0" background
                       layout="total,prev, pager, next,jumper" :page-size="pageSize||10"
                       :current-page="(params&&params.page)||pageInfo.page"
                       :total="(params&&params.total)||pageInfo.total" @current-change="pageChange"></el-pagination>

    </div>
</template>
<script>
    import TableHead from "./tableHead";
    import TableContent from "./tableContent";
    import TableContent1 from "./tableContent1"
    export default {
        props: ["btns", "tableData", "table", "hideHead", "delUrl", "type", "tableTotable", "params", "data0", "search", "pageSize", "url", "index"],
        components: {TableHead, TableContent, TableContent1},
        name: "",
        data() {
            return {
                pageInfo: {
                    total: 0,
                    page: 1,
                },

                type0: "",
                data: []
            };
        },
        computed: {
            getTable() {
                return this.tableTotable ? "TableContent1" : "TableContent"
            }
        },
        methods: {
            getTableData() {
                var params = {
                    number: localStorage.getItem("userNumber"),
                    page: this.pageInfo.page,
                    table: this.table,
                    tablename: this.pageInfo.tablename
                }
                var formatKeys = ["date", "start_date", "training_date"]
                for (var key in this.$store.state.search.params) {
                    if (this.$store.state.search.params[key] && this.$store.state.search.params[key].length > 0) params[key] = formatKeys.includes(key) ? [_g.formatTime(this.$store.state.search.params[key][0]), _g.formatTime(this.$store.state.search.params[key][1])] : this.$store.state.search.params[key]
                }
                if (this.type) params.type = this.type0 || this.type

                // this.apiPost(this.url||"teacher_manage/infoList",params).then(res=>{
                //   this.pageInfo.total=res.total
                //   this.data=res.list
                // })
            },
            pageChange(page) {
                this.pageInfo.page = page
                if (this.params) this.params.page = page
                var path = _g.getRouterPath(this)
                if (path != "/student") this.getTableData()
            }
        },
        created() {
            var path = _g.getRouterPath(this)
            // if(path!="/student"&&path!="/student/only"){
            //   this.getTableData()
            //   this.$store.state.downLoadExcel.tableName=this.table
            //   this.$store.state.downLoadExcel.data=this.tableData

            //   if(bus._events.flashSocialTable&&bus._events.flashSocialTable.length>0)bus._events.flashSocialTable.shift()
            //   bus.$on("flashSocialTable",()=>{
            //     this.pageInfo.page=1
            //     this.getTableData()
            //   })
            //   bus.$on("changeRelation",(val)=>{
            //     this.type0=val
            //     this.getTableData()

            //   })
            // }
        },
        beforeDestroy() {
            // bus.$off("flashSocialTable")
        },
    };
</script>
<style scoped>
    .table-box {
        margin-top: 20px;
    }
</style>